package com.genesis.web.controller.member;

import com.genesis.mall.common.Result;
import com.genesis.mall.dto.PageDto;
import com.genesis.mall.entity.MemberProductCollection;
import com.genesis.mall.service.IMemberProductCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: HShuai
 * @Date: 2022/08/03/20:44星期三
 * @Description:   用户收藏商品
 */

@RestController
@RequestMapping("/member/productCollection")
public class MemberProductCollectionController {

    @Autowired
    private IMemberProductCollectionService memberProductCollectionService;

    /**
     * 添加商品收藏
     *
     * @param memberProductCollection
     * @return
     */
    @PostMapping("/add")
    public Result save(@RequestBody MemberProductCollection memberProductCollection) {
        memberProductCollectionService.saveProduct(memberProductCollection);
        return Result.success();
    }

    /**
     * 清空当前用户商品收藏列表
     * @param request
     * @return
     */
    @PostMapping("/clear")
    public Result clear(HttpServletRequest request) {
        memberProductCollectionService.clearById(request);
        return Result.success();
    }

    /**
     * 删除商品收藏
     * @param productId
     * @param request
     * @return
     */
    @PostMapping("/delete")
    public Result deleteById(@RequestParam Long productId,HttpServletRequest request){
        memberProductCollectionService.deleteById(productId,request);
        return Result.success();
    }

    /**
     * 显示商品收藏详情
     * @param productId
     * @param request
     * @return
     */
    @GetMapping("/detail")
    public Result<MemberProductCollection> getDetail( Long productId,HttpServletRequest request){
            return Result.success(memberProductCollectionService.getDetail(productId,request));
    }

    /**
     * 显示当前用户商品收藏列表
     * @param request
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result<PageDto<MemberProductCollection>> pageDtoResult (HttpServletRequest request,Integer pageNum,Integer pageSize){

        return Result.success(memberProductCollectionService.pageList(request,pageNum,pageSize));
    }
}
